<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SPAM3-UK Ford汽车信息测试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #003f82;
            text-align: center;
            margin-bottom: 30px;
        }
        .filters {
            background-color: #f8f9fa;
            padding: 20px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        .filter-row {
            display: flex;
            gap: 15px;
            margin-bottom: 10px;
            flex-wrap: wrap;
        }
        .filter-group {
            display: flex;
            flex-direction: column;
            min-width: 150px;
        }
        label {
            font-weight: bold;
            margin-bottom: 5px;
            color: #333;
        }
        input, select {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }
        button {
            background-color: #003f82;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            margin: 5px;
        }
        button:hover {
            background-color: #002952;
        }
        .loading {
            text-align: center;
            padding: 20px;
            color: #666;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
            padding: 15px;
            border-radius: 4px;
            margin: 10px 0;
        }
        .stats {
            background-color: #d4edda;
            color: #155724;
            padding: 15px;
            border-radius: 4px;
            margin: 10px 0;
        }
        .vehicle-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }
        .vehicle-card {
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 15px;
            background-color: white;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        .vehicle-title {
            font-size: 18px;
            font-weight: bold;
            color: #003f82;
            margin-bottom: 10px;
        }
        .vehicle-info {
            display: flex;
            justify-content: space-between;
            margin: 5px 0;
        }
        .price {
            font-size: 16px;
            font-weight: bold;
            color: #28a745;
        }
        .vehicle-type {
            display: inline-block;
            padding: 3px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: bold;
            text-transform: uppercase;
        }
        .type-car { background-color: #007bff; color: white; }
        .type-van { background-color: #28a745; color: white; }
        .type-pickup { background-color: #ffc107; color: black; }
        .type-hybrid_electric { background-color: #28a745; color: white; }
        .type-suv_crossovers { background-color: #6c757d; color: white; }
        .type-performance { background-color: #dc3545; color: white; }
        .type-people_movers { background-color: #6f42c1; color: white; }
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 20px 0;
            gap: 10px;
        }
        .pagination button {
            padding: 8px 12px;
            font-size: 14px;
        }
        .pagination span {
            padding: 8px 12px;
            background-color: #e9ecef;
            border-radius: 4px;
        }
        .trim-btn, .scrape-btn {
            flex: 1;
            padding: 8px 12px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
            font-weight: bold;
        }
        .trim-btn {
            background-color: #007bff;
            color: white;
        }
        .trim-btn:hover {
            background-color: #0056b3;
        }
        .scrape-btn {
            background-color: #28a745;
            color: white;
        }
        .scrape-btn:hover {
            background-color: #1e7e34;
        }
        .scrape-btn:disabled {
            background-color: #6c757d;
            cursor: not-allowed;
            opacity: 0.6;
        }
        .scrape-btn.loading {
            background-color: #ffc107;
            color: #000;
            cursor: not-allowed;
        }
        .scrape-btn.loading::after {
            content: " ⏳";
        }
        .trim-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            z-index: 1000;
        }
        .trim-modal-content {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            width: 90%;
            max-width: 800px;
            max-height: 80%;
            overflow-y: auto;
            border-radius: 8px;
            padding: 20px;
        }
        .trim-card {
            border: 1px solid #ddd;
            border-radius: 6px;
            padding: 15px;
            margin-bottom: 15px;
            background-color: #f8f9fa;
        }
        .trim-title {
            font-size: 16px;
            font-weight: bold;
            color: #003f82;
            margin-bottom: 10px;
        }
        .spec-category {
            font-weight: bold;
            color: #495057;
            margin-top: 10px;
            margin-bottom: 5px;
        }
        .spec-item {
            display: flex;
            justify-content: space-between;
            margin: 3px 0;
            font-size: 14px;
        }
        .close-modal {
            position: absolute;
            top: 10px;
            right: 15px;
            background: none;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: #666;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🚗 SPAM3-UK Ford汽车信息测试系统</h1>
        
        <!-- 筛选器 -->
        <div class="filters">
            <h3>筛选条件</h3>
            <div class="filter-row">
                <div class="filter-group">
                    <label for="vehicleCategory">Ford分类:</label>
                    <select id="vehicleCategory">
                        <option value="">全部分类</option>
                        <option value="hybrid_electric">Hybrid & Electric</option>
                        <option value="suv_crossovers">SUV & Crossovers</option>
                        <option value="performance">Performance</option>
                        <option value="people_movers">People Movers</option>
                    </select>
                </div>
                <div class="filter-group">
                    <label for="vehicleType">车辆类型:</label>
                    <select id="vehicleType">
                        <option value="">全部</option>
                        <option value="Electric SUV">电动SUV</option>
                        <option value="Sports Car">跑车</option>
                        <option value="Hot Hatch">钢炮</option>
                        <option value="Large MPV">大型MPV</option>
                        <option value="Compact SUV">紧凑SUV</option>
                    </select>
                </div>
                <div class="filter-group">
                    <label for="make">品牌:</label>
                    <input type="text" id="make" placeholder="Ford">
                </div>
                <div class="filter-group">
                    <label for="model">车型:</label>
                    <input type="text" id="model" placeholder="Fiesta, Focus...">
                </div>
                <div class="filter-group">
                    <label for="minPrice">最低价格:</label>
                    <input type="number" id="minPrice" placeholder="0">
                </div>
                <div class="filter-group">
                    <label for="maxPrice">最高价格:</label>
                    <input type="number" id="maxPrice" placeholder="100000">
                </div>
            </div>
            <div class="filter-row">
                <div class="filter-group">
                    <label for="fuelType">燃料类型:</label>
                    <select id="fuelType">
                        <option value="">全部</option>
                        <option value="Petrol">汽油</option>
                        <option value="Diesel">柴油</option>
                        <option value="Electric">电动</option>
                        <option value="Hybrid">混合动力</option>
                        <option value="Plug-in Hybrid">插电混动</option>
                        <option value="Mild Hybrid">轻混</option>
                    </select>
                </div>
                <div class="filter-group">
                    <label for="pageSize">每页显示:</label>
                    <select id="pageSize">
                        <option value="10">10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                    </select>
                </div>
                <div class="filter-group">
                    <label>&nbsp;</label>
                    <div>
                        <button onclick="loadVehicles()">搜索</button>
                        <button onclick="clearFilters()">清空</button>
                        <button onclick="testAPI()">测试API</button>
                        <button onclick="loadCategories()">分类统计</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 统计信息 -->
        <div id="stats" class="stats" style="display: none;"></div>
        
        <!-- 错误信息 -->
        <div id="error" class="error" style="display: none;"></div>
        
        <!-- 加载状态 -->
        <div id="loading" class="loading" style="display: none;">加载中...</div>
        
        <!-- 分页控件 -->
        <div id="pagination" class="pagination" style="display: none;"></div>
        
        <!-- 车辆信息网格 -->
        <div id="vehicleGrid" class="vehicle-grid"></div>
        
        <!-- Trim配置模态框 -->
        <div id="trimModal" class="trim-modal">
            <div class="trim-modal-content">
                <button class="close-modal" onclick="closeTrimModal()">&times;</button>
                <h2 id="trimModalTitle">车型配置信息</h2>
                <div id="trimContent">加载中...</div>
            </div>
        </div>
    </div>

    <script>
        let currentPage = 1;
        let totalPages = 1;
        let totalCount = 0;
        
        // 防抖和状态管理
        let isScraping = false;
        let scrapeTimeout = null;
        const SCRAPE_DEBOUNCE_DELAY = 2000; // 2秒防抖延迟

        // 页面加载时获取数据
        document.addEventListener('DOMContentLoaded', function() {
            loadVehicles();
        });

        // 加载车辆数据
        async function loadVehicles(page = 1) {
            showLoading(true);
            hideError();
            
            currentPage = page;
            
            // 构建查询参数
            const params = new URLSearchParams();
            
            const vehicleCategory = document.getElementById('vehicleCategory').value;
            const vehicleType = document.getElementById('vehicleType').value;
            const make = document.getElementById('make').value;
            const model = document.getElementById('model').value;
            const minPrice = document.getElementById('minPrice').value;
            const maxPrice = document.getElementById('maxPrice').value;
            const fuelType = document.getElementById('fuelType').value;
            const pageSize = document.getElementById('pageSize').value;
            
            if (vehicleCategory) params.append('vehicle_category', vehicleCategory);
            if (vehicleType) params.append('vehicle_type', vehicleType);
            if (make) params.append('make', make);
            if (model) params.append('model', model);
            if (minPrice) params.append('min_price', minPrice);
            if (maxPrice) params.append('max_price', maxPrice);
            if (fuelType) params.append('fuel_type', fuelType);
            params.append('page', page);
            params.append('page_size', pageSize);
            
            try {
                const response = await fetch(`/api/get_all_cars?${params.toString()}`);
                
                if (!response.ok) {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }
                
                const data = await response.json();
                
                if (data.code === 200) {
                    displayVehicles(data.data);
                    totalCount = data.total;
                    totalPages = Math.ceil(totalCount / parseInt(pageSize));
                    updatePagination();
                    showStats(data.total, data.data.length);
                } else {
                    showError('API返回错误: ' + data.message);
                }
            } catch (error) {
                showError('加载失败: ' + error.message);
                console.error('Error loading vehicles:', error);
            } finally {
                showLoading(false);
            }
        }

        // 显示车辆信息
        function displayVehicles(vehicles) {
            const grid = document.getElementById('vehicleGrid');
            
            if (!vehicles || vehicles.length === 0) {
                grid.innerHTML = '<div style="text-align: center; padding: 40px; color: #666;">没有找到车辆信息</div>';
                return;
            }
            
            grid.innerHTML = vehicles.map(vehicle => `
                <div class="vehicle-card">
                    <div class="vehicle-title">
                        ${vehicle.make} ${vehicle.model}
                        <span class="vehicle-type type-${vehicle.vehicle_category}">${getCategoryText(vehicle.vehicle_category)}</span>
                    </div>
                    <div class="vehicle-info">
                        <span>分类:</span>
                        <span>${getCategoryDisplayName(vehicle.vehicle_category)}</span>
                    </div>
                    <div class="vehicle-info">
                        <span>变体:</span>
                        <span>${vehicle.variant || '未指定'}</span>
                    </div>
                    <div class="vehicle-info">
                        <span>价格:</span>
                        <span class="price">
                            ${formatPrice(vehicle.price_from, vehicle.price_to)}
                        </span>
                    </div>
                    <div class="vehicle-info">
                        <span>燃料:</span>
                        <span>${vehicle.fuel_type || '未指定'}</span>
                    </div>
                    <div class="vehicle-info">
                        <span>变速箱:</span>
                        <span>${vehicle.transmission || '未指定'}</span>
                    </div>
                    <div class="vehicle-info">
                        <span>车身:</span>
                        <span>${vehicle.body_style || '未指定'}</span>
                    </div>
                    <div class="vehicle-info">
                        <span>状态:</span>
                        <span>${vehicle.availability || '未知'}</span>
                    </div>
                    ${vehicle.description ? `<div style="margin-top: 10px; font-size: 12px; color: #666;">${vehicle.description}</div>` : ''}
                    <div class="trim-actions" style="margin-top: 15px; display: flex; gap: 10px;">
                        <button onclick="showTrims('${vehicle.model}')" class="trim-btn">查看配置</button>
                        <button onclick="scrapeTrims('${vehicle.model}')" class="scrape-btn">抓取配置</button>
                    </div>
                </div>
            `).join('');
        }

        // 更新分页
        function updatePagination() {
            const pagination = document.getElementById('pagination');
            
            if (totalPages <= 1) {
                pagination.style.display = 'none';
                return;
            }
            
            pagination.style.display = 'flex';
            
            let paginationHTML = '';
            
            // 上一页
            if (currentPage > 1) {
                paginationHTML += `<button onclick="loadVehicles(${currentPage - 1})">上一页</button>`;
            }
            
            // 页码
            const startPage = Math.max(1, currentPage - 2);
            const endPage = Math.min(totalPages, currentPage + 2);
            
            for (let i = startPage; i <= endPage; i++) {
                if (i === currentPage) {
                    paginationHTML += `<span style="background-color: #003f82; color: white;">${i}</span>`;
                } else {
                    paginationHTML += `<button onclick="loadVehicles(${i})">${i}</button>`;
                }
            }
            
            // 下一页
            if (currentPage < totalPages) {
                paginationHTML += `<button onclick="loadVehicles(${currentPage + 1})">下一页</button>`;
            }
            
            pagination.innerHTML = paginationHTML;
        }

        // 显示统计信息
        function showStats(total, current) {
            const stats = document.getElementById('stats');
            stats.innerHTML = `📊 共找到 ${total} 辆车辆，当前显示第 ${currentPage} 页 (${current} 辆)`;
            stats.style.display = 'block';
        }

        // 显示错误
        function showError(message) {
            const error = document.getElementById('error');
            error.innerHTML = '❌ ' + message;
            error.style.display = 'block';
        }

        // 隐藏错误
        function hideError() {
            document.getElementById('error').style.display = 'none';
        }

        // 显示/隐藏加载状态
        function showLoading(show) {
            document.getElementById('loading').style.display = show ? 'block' : 'none';
        }

        // 清空筛选器
        function clearFilters() {
            document.getElementById('vehicleCategory').value = '';
            document.getElementById('vehicleType').value = '';
            document.getElementById('make').value = '';
            document.getElementById('model').value = '';
            document.getElementById('minPrice').value = '';
            document.getElementById('maxPrice').value = '';
            document.getElementById('fuelType').value = '';
            document.getElementById('pageSize').value = '10';
            loadVehicles();
        }

        // 测试API连接
        async function testAPI() {
            showLoading(true);
            hideError();
            
            try {
                const response = await fetch('/health');
                const data = await response.json();
                
                if (response.ok) {
                    alert('✅ API连接正常！\n' + 
                          '服务: ' + data.service + '\n' + 
                          '版本: ' + data.version + '\n' + 
                          '状态: ' + data.status);
                } else {
                    throw new Error('健康检查失败');
                }
            } catch (error) {
                showError('API连接测试失败: ' + error.message);
            } finally {
                showLoading(false);
            }
        }

        // 工具函数
        function getVehicleTypeText(type) {
            const types = {
                'car': '轿车',
                'van': '面包车',
                'pickup': '皮卡'
            };
            return types[type] || type;
        }

        function getCategoryText(category) {
            const categories = {
                'hybrid_electric': 'HE',
                'suv_crossovers': 'SUV',
                'performance': 'PERF',
                'people_movers': 'PM'
            };
            return categories[category] || category?.toUpperCase();
        }

        function getCategoryDisplayName(category) {
            const categories = {
                'hybrid_electric': 'Hybrid & Electric',
                'suv_crossovers': 'SUV & Crossovers',
                'performance': 'Performance',
                'people_movers': 'People Movers'
            };
            return categories[category] || category;
        }

        function formatPrice(priceFrom, priceTo) {
            if (!priceFrom && !priceTo) return '暂无报价';
            if (!priceTo || priceFrom === priceTo) return `£${priceFrom?.toLocaleString()}`;
            return `£${priceFrom?.toLocaleString()} - £${priceTo?.toLocaleString()}`;
        }

        // 加载分类统计信息
        async function loadCategories() {
            showLoading(true);
            hideError();
            
            try {
                const response = await fetch('/api/categories');
                const data = await response.json();
                
                if (response.ok && data.code === 200) {
                    let statsHTML = '📊 Ford车辆分类统计:<br><br>';
                    data.data.forEach(cat => {
                        const actual = data.stats[cat.category] || 0;
                        const status = actual === cat.expected_count ? '✅' : '⚠️';
                        statsHTML += `${status} <strong>${cat.display_name}</strong>: ${actual}/${cat.expected_count}辆<br>`;
                    });
                    
                    const stats = document.getElementById('stats');
                    stats.innerHTML = statsHTML;
                    stats.style.display = 'block';
                } else {
                    throw new Error('获取分类信息失败');
                }
            } catch (error) {
                showError('分类统计加载失败: ' + error.message);
            } finally {
                showLoading(false);
            }
        }

        // Trim相关功能
        async function showTrims(model) {
            const modal = document.getElementById('trimModal');
            const title = document.getElementById('trimModalTitle');
            const content = document.getElementById('trimContent');
            
            title.textContent = `${model} 配置信息`;
            content.innerHTML = '加载中...';
            modal.style.display = 'block';
            
            try {
                const response = await fetch(`/api/get_trims?model=${encodeURIComponent(model)}`);
                
                if (response.ok) {
                    const data = await response.json();
                    displayTrims(data);
                } else if (response.status === 404) {
                    content.innerHTML = `
                        <div style="text-align: center; padding: 40px;">
                            <p>暂无 ${model} 的配置信息</p>
                            <button onclick="scrapeTrims('${model}')" class="scrape-btn" style="margin-top: 10px;">
                                点击抓取配置数据
                            </button>
                        </div>
                    `;
                } else {
                    const errorData = await response.json();
                    content.innerHTML = `<div style="color: red; text-align: center; padding: 20px;">加载失败: ${errorData.message}</div>`;
                }
            } catch (error) {
                content.innerHTML = `<div style="color: red; text-align: center; padding: 20px;">网络错误: ${error.message}</div>`;
            }
        }

        // 防抖函数
        function debounce(func, delay) {
            return function(...args) {
                clearTimeout(scrapeTimeout);
                scrapeTimeout = setTimeout(() => func.apply(this, args), delay);
            };
        }

        // 禁用所有抓取按钮
        function disableAllScrapeButtons() {
            const buttons = document.querySelectorAll('.scrape-btn');
            buttons.forEach(btn => {
                btn.disabled = true;
                btn.classList.add('loading');
            });
        }

        // 启用所有抓取按钮
        function enableAllScrapeButtons() {
            const buttons = document.querySelectorAll('.scrape-btn');
            buttons.forEach(btn => {
                btn.disabled = false;
                btn.classList.remove('loading');
            });
        }

        // 防抖的抓取函数
        const debouncedScrapeTrims = debounce(async function(model) {
            if (isScraping) {
                console.log('抓取正在进行中，请稍候...');
                return;
            }

            isScraping = true;
            disableAllScrapeButtons();

            const content = document.getElementById('trimContent');
            content.innerHTML = `
                <div style="text-align: center; padding: 20px;">
                    <div style="color: #ffc107; font-size: 18px; margin-bottom: 10px;">
                        ⏳ 正在抓取 ${model} 的配置数据...
                    </div>
                    <div style="color: #666; font-size: 14px;">
                        请勿关闭页面，抓取可能需要几秒钟时间
                    </div>
                </div>
            `;
            
            try {
                const response = await fetch(`/api/scrape_trims?model=${encodeURIComponent(model)}`, {
                    method: 'POST'
                });
                
                if (response.ok) {
                    const data = await response.json();
                    content.innerHTML = `
                        <div style="color: green; text-align: center; padding: 20px;">
                            <div style="font-size: 18px; margin-bottom: 10px;">
                                ✅ 成功抓取 ${data.data.trims_count} 个配置
                            </div>
                            <div style="color: #666; font-size: 14px; margin-bottom: 15px;">
                                抓取完成时间: ${new Date().toLocaleTimeString()}
                            </div>
                            <button onclick="showTrims('${model}')" class="trim-btn">
                                查看配置详情
                            </button>
                        </div>
                    `;
                } else {
                    const errorData = await response.json();
                    content.innerHTML = `
                        <div style="color: red; text-align: center; padding: 20px;">
                            <div style="font-size: 18px; margin-bottom: 10px;">
                                ❌ 抓取失败
                            </div>
                            <div style="color: #666; font-size: 14px;">
                                ${errorData.message}
                            </div>
                            <button onclick="scrapeTrims('${model}')" class="scrape-btn" style="margin-top: 10px;">
                                重试抓取
                            </button>
                        </div>
                    `;
                }
            } catch (error) {
                content.innerHTML = `
                    <div style="color: red; text-align: center; padding: 20px;">
                        <div style="font-size: 18px; margin-bottom: 10px;">
                            ❌ 网络错误
                        </div>
                        <div style="color: #666; font-size: 14px;">
                            ${error.message}
                        </div>
                        <button onclick="scrapeTrims('${model}')" class="scrape-btn" style="margin-top: 10px;">
                            重试抓取
                        </button>
                    </div>
                `;
            } finally {
                isScraping = false;
                enableAllScrapeButtons();
            }
        }, SCRAPE_DEBOUNCE_DELAY);

        // 用户点击的抓取函数（带防抖）
        async function scrapeTrims(model) {
            if (isScraping) {
                alert('⚠️ 抓取正在进行中，请稍候...');
                return;
            }

            // 显示防抖提示
            const content = document.getElementById('trimContent');
            const delaySeconds = SCRAPE_DEBOUNCE_DELAY / 1000;
            content.innerHTML = `
                <div style="text-align: center; padding: 20px;">
                    <div style="color: #ffc107; font-size: 16px; margin-bottom: 10px;">
                        ⏳ 准备抓取中...
                    </div>
                    <div style="color: #666; font-size: 14px;">
                        将在 ${delaySeconds} 秒后开始抓取
                    </div>
                </div>
            `;

            // 调用防抖函数
            debouncedScrapeTrims(model);
        }

        function displayTrims(data) {
            const content = document.getElementById('trimContent');
            
            if (!data.trims || data.trims.length === 0) {
                content.innerHTML = '<div style="text-align: center; padding: 20px;">暂无配置信息</div>';
                return;
            }
            
            let html = `
                <div style="margin-bottom: 15px;">
                    <strong>车型:</strong> ${data.model_name} 
                    <span style="color: #666;">(共 ${data.total_trims} 个配置)</span>
                </div>
            `;
            
            data.trims.forEach(trim => {
                html += `
                    <div class="trim-card">
                        <div class="trim-title">
                            ${trim.trim_info.trim_display_name}
                            <span style="float: right; color: #28a745; font-weight: bold;">
                                £${trim.trim_info.price_from.toLocaleString()}
                            </span>
                        </div>
                        <div style="margin-bottom: 10px; color: #666;">
                            ${trim.trim_info.doors} 门 | 
                            ${trim.trim_info.battery_capacity || '—'} | 
                            ${trim.trim_info.range_miles || '—'}
                        </div>
                `;
                
                // 显示规格信息
                Object.keys(trim.specifications).forEach(category => {
                    if (trim.specifications[category].length > 0) {
                        html += `<div class="spec-category">${category}</div>`;
                        trim.specifications[category].forEach(spec => {
                            html += `
                                <div class="spec-item">
                                    <span>${spec.spec_name}:</span>
                                    <span>${spec.spec_value} ${spec.spec_unit}</span>
                                </div>
                            `;
                        });
                    }
                });
                
                html += '</div>';
            });
            
            content.innerHTML = html;
        }

        function closeTrimModal() {
            document.getElementById('trimModal').style.display = 'none';
        }

        // 点击模态框外部关闭
        window.onclick = function(event) {
            const modal = document.getElementById('trimModal');
            if (event.target === modal) {
                modal.style.display = 'none';
            }
        }
    </script>
</body>
</html>
